package com.situ.library.service.impl;

import com.situ.library.dao.ICardDao;
import com.situ.library.dao.impl.CardDaoImpl;
import com.situ.library.pojo.entity.Card;
import com.situ.library.pojo.query.CardQuery;
import com.situ.library.pojo.vo.CardVO;
import com.situ.library.service.ICardService;
import com.situ.library.util.PageInfo;

import java.util.List;

public class CardServiceImpl implements ICardService {
    private ICardDao cardDao = new CardDaoImpl();

    @Override
    public PageInfo selectByPage(CardQuery cardQuery) {
        List<CardVO> list = cardDao.selectByPage(cardQuery);
        //现在要搜索的是符合条件的总的数量
        int totalCount = cardDao.selectTotalCount(cardQuery);

        return  PageInfo.ok(totalCount, list);
    }

    @Override
    public void deleteById(int id) {
        cardDao.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        //delete from card where id in(2, 4, 5);
        for (String id : ids) {
            cardDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Card card) {
        cardDao.add(card);
    }

    @Override
    public void update(Card card) {
        cardDao.update(card);
    }

    @Override
    public Card selectById(int id) {
        return cardDao.selectById(id);
    }

    @Override
    public List<Card> selectAll() {
        return cardDao.selectAll();
    }

    @Override
    public void updateStatus(int id, int status) {
        cardDao.updateStatus(id, status);
    }

}
